package com.xinchuang.utils;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author zkwczx
 * @version 1.0
 * @date 2023/9/21 10:41
 */
@Component
public class FileLoader {

    private ResourceLoader resourceLoader;

    public FileLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    public List<Path> getAllFiles() throws IOException {
        List<Path> fileList = new ArrayList<>();
        Resource resource = resourceLoader.getResource("classpath:/type");
        Path folder = resource.getFile().toPath();
        Files.walk(folder)
                .filter(Files::isRegularFile)
                .forEach(fileList::add);
        return fileList;
    }

}
